<template>
  <el-table
    :key="tableKey"
    v-loading="listLoading"
    :data="list"
    border
    highlight-current-row
    style="width: 100%;"
  >
    <el-table-column
      label="编号"
      prop="id"
      sortable
      align="center"
      width="90px"
      type="index"
      :index="indexMethod"
    />
    <el-table-column label="名称" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row}">
        <span>{{ row.entName }}</span>
      </template>
    </el-table-column>
    <el-table-column label="省份" align="center">
      <template slot-scope="{row}">
        <span>{{ row.province }}</span>
      </template>
    </el-table-column>
    <el-table-column label="城市" align="center">
      <template slot-scope="{row}">
        <span>{{ row.city }}</span>
      </template>
    </el-table-column>
    <el-table-column label="区、县" align="center">
      <template slot-scope="{row}">
        <span>{{ row.county }}</span>
      </template>
    </el-table-column>
    <el-table-column label="详细地址" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row}">
        <span>{{ row.location }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="操作"
      align="center"
      min-width="150px"
      class-name="small-padding fixed-width"
    >
      <template slot-scope="{row, $index}">
        <el-button type="danger" size="mini" @click="handleDelete(row.entId, $index)">删除</el-button>
        <el-button type="primary" size="mini" @click="handleModify(row)">编辑</el-button>
        <el-button
          type="success"
          size="mini"
          @click="routePages({entId: row.entId}, '/enterprise/image')"
        >详情</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'MyTable',
  props: {
    list: {
      type: Array,
      required: true
    },
    listLoading: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      tableKey: 0
    }
  },
  methods: {
    handleDelete(entId, index) {
      this.$confirm('确定删除所选企业吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$emit('delete', entId, index)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    handleModify(row) {
      this.$emit('modify', row)
    },
    indexMethod(index) {
      return index + 1
    },
    routePages(query, url) {
      this.$router.push({
        path: url,
        query
      })
    }
  }
}
</script>
